package com.sport.service.impl;

import com.sport.bean.PageParam;
import com.sport.bean.StuTake;
import com.sport.bean.Student;
import com.sport.dao.StudentDao;
import com.sport.service.IStudentService;
import com.sun.xml.internal.ws.api.message.HeaderList;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class StudentServiceImpl implements IStudentService {
    @Autowired
    private  IStudentService studentService;
    @Autowired
    private StudentDao studentDao;
//    //查找所有学生
    @Override
    public List<Student> findAll() {
        return studentDao.findAll();
    }
    //根据学生id查找
    @Override
    public Student findById(Integer id) {
        return studentDao.findById(id);
    }

    //根据学生名字查找
    @Override
    public Student findByName(String stuname) {
        return studentDao.findByName(stuname);
    }
    //根据学号查找是否相同
    @Override
    public Student findByStuno(String stuno) {
        return studentDao.findByStuno(stuno);
    }

    //更新学生
    @Override
    public int updateStu(Student student) {
        return studentDao.updateStu(student);
    }
    //添加学生
    @Override
    public int addStudent(Student student) {
        return studentDao.addStudent(student);
    }
    //删除学生
    @Override
    public int deletStudent(Integer id) {
        return studentDao.deletStudent(id);
    }
    //分页查询学生
    @Override
    public List<Student> listPage(PageParam<Student> pageParam) {
        return studentDao.listPage(pageParam);
    }

    @Override
    public List<Student> listStudent() {
//        Map map = new HashMap();
        List<Student> list=studentDao.listStudent();
//        List list1=new ArrayList();
        for (int i = 0; i <list.size() ; i++) {
            StuTake stuTake=list.get(i).getStuTakes().get(0);
            list.get(i).setAchievement(stuTake.getAchievement());
//            map.put("id",list.get(i).getId());
//            map.put("stuNo",list.get(i).getStuNo());
//            map.put("stuName",list.get(i).getStuName());
//            map.put("gender",list.get(i).getGender());
//            map.put("age",list.get(i).getAge());
//            map.put("college",list.get(i).getId());
//            map.put("major",list.get(i).getId());
//            map.put("className",list.get(i).getId());
//            map.put("tel",list.get(i).getId());
//            map.put("email",list.get(i).getId());
//            map.put("deleted",list.get(i).getId());
//            map.put("achievement",stuTake.getAchievement());

        }
        return list;
    }

    @Override
    public int updateInfo(Student student) {
        return studentDao.updateStu(student);
    }
}
